import { Request, Response } from 'express';
import { parse } from 'url';

// 生成模拟员工数据
const genEmployeeList = (count: number) => {
  const list = Array.from({ length: count }).map((_, i) => {
    return {
      imei: `imei_${i}`,
      nickName: `员工${i}`,
      sex: Math.random() > 0.5 ? '男' : '女',
      age: Math.floor(Math.random() * 30) + 20,
      jobPost: ['开发', '测试', '产品', '设计', '运营'][Math.floor(Math.random() * 5)],
      jobDutyName: ['初级', '中级', '高级', '专家'][Math.floor(Math.random() * 4)],
      member: Math.random() > 0.5 ? '是' : '否',
      departName: ['技术部', '产品部', '设计部', '运营部', '市场部'][Math.floor(Math.random() * 5)],
    };
  });
  return list;
};

// 处理获取员工列表的请求
function getEmployeeList(req: Request, res: Response) {
  // 模拟后端API的响应格式
  const employeeList = genEmployeeList(100);
  
  // 获取请求体中的memberId
  const { memberId } = req.body;
  
  // 返回模拟数据
  return res.json({
    code: 0,
    msg: 'success',
    data: {
      list: employeeList,
      total: employeeList.length,
      memberId: memberId || 100067
    }
  });
}

// 处理删除员工的请求
function removeEmployee(req: Request, res: Response) {
  const { ids } = req.body;
  return res.json({
    code: 0,
    msg: '删除成功',
    data: { ids }
  });
}

export default {
  'POST /dataAnalysis/card/getCards': getEmployeeList,
  'DELETE /api/employee': removeEmployee,
};